﻿using UnityEngine;
using System.Collections;

public class coinScript : MonoBehaviour {
	
	public moneyPouchScript mPouch;
	public bool firstTouch;
	
	// Use this for initialization
	void Start () {
		firstTouch = true;
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	public void flyToCoinPlace()
	{
		TweenPosition tp = GetComponent<TweenPosition>();
		tp.from = transform.localPosition;
		//-7.2,2.5
		transform.localPosition = new Vector3(400,-100,0);
		Vector3 tmpPos = transform.InverseTransformPoint(mPouch.coinLabel.transform.position);
		tp.to = tmpPos;
		tp.to.x += 300;
		tp.to.y -= 100;
		//Debug.Log(tp.to);
		//tp.to = new Vector3(128,365,0);
		//Debug.Log(transform.position);
		tp.Reset();
		tp.delay = 0.4f;
		tp.duration = 1.0f;
		//tp.callWhenFinished = "";
		tp.onFinished.Add(new EventDelegate(this,"ff1"));
		tp.onFinished.Remove(new EventDelegate(this,"flyToCoinPlace"));
		//tp.eventReceiver = null;
		tp.Play(true);
	}
	
	public void ff1()
	{
		if(firstTouch)
		{
			firstTouch = false;
			return;
		}
			Debug.Log(transform.localPosition);
		mPouch.addMoney(100);
	}
	
	
}
